import { patchRouter } from '../utils'
import { turnApp } from './routerHandle'

export const rewriteRouter = () => {
    window.history.pushState = patchRouter(window.history.pushState, 'micro_push')
    window.history.replaceState = patchRouter(window.history.replaceState, 'micro_replace')

    window.addEventListener('micro_push', turnApp)
    window.addEventListener('micro_replace', turnApp)

    // 监听浏览器前进后退
    window.onpopstate = () => {
        turnApp()
    }
}
